<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>微博首页</h1>
<div>
    <div v-if="user!=null">
        <h3>欢迎{{user.nickname}}回来!</h3>
        <a href="/list.html">微博列表</a>
        <!--javascript:void(0) 禁用跳转-->
        <a href="javascript:void(0)" @click="logout()">退出登录</a>
    </div>
    <div v-else>
        <a href="/reg.html">注册</a>
        <a href="/login.html">登录</a>
    </div>

</div>
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!--引入Axios框架-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script>
    let v = new Vue({
        el: "body>div",
        data: {
            user: localStorage.user ? JSON.parse(localStorage.user) : null
        },
        methods: {
            logout() {
                if (confirm("您确认退出登录吗?")) {
                    axios.get("/v1/users/logout").then(function (response) {
                        if (response.data.code == 1) {
                            //清除localStorage里面的数据
                            localStorage.clear();
                            location.reload();//刷新页面
                        }
                    })
                }
            }
        }
    })
</script>
</body>
</html>